package doc

import (
	"encoding/json"
	"fmt"
)

func main1() {
	//utils.InitConfig()
	//utils.InitMysql()
	//utils.InitRedis()
	//router.Router()
}

func main2() {
	//service.OpeExcelData() // 测试账单读写
	//utils.InitConfig()
	//utils.InitMysql()
	//service.AddUser()
	//service.AllRun()
}

// GetApprovalWorkflowConfigData 请求获取审批配置的列表页面返回结果
type GetApprovalWorkflowConfigData struct {
	ProjectId          string
	ProjectName        string
	RegionName         string
	RegionId           string
	BizScene           string
	Index              int32
	NodeId             string
	NodeName           string
	NodeOrder          int32
	NodeApproverEnname string
	NodeApproverCnname string
	Status             int32
}

type ApprovalWorkflowsNodeApprovers struct {
	NodeApproverEnname string `protobuf:"bytes,1,opt,name=node_approver_enname,json=nodeApproverEnname,proto3" json:"node_approver_enname,omitempty"`
	NodeApproverCnname string `protobuf:"bytes,2,opt,name=node_approver_cnname,json=nodeApproverCnname,proto3" json:"node_approver_cnname,omitempty"`
	Status             int32  `protobuf:"varint,3,opt,name=status,proto3" json:"status,omitempty"`
}

type ApprovalWorkflowsNodeList struct {
	NodeId        string                            `protobuf:"bytes,1,opt,name=node_id,json=nodeId,proto3" json:"node_id,omitempty"`
	NodeName      string                            `protobuf:"bytes,2,opt,name=node_name,json=nodeName,proto3" json:"node_name,omitempty"`
	NodeOrder     int32                             `protobuf:"varint,3,opt,name=node_order,json=nodeOrder,proto3" json:"node_order,omitempty"`
	NodeApprovers []*ApprovalWorkflowsNodeApprovers `protobuf:"bytes,4,rep,name=node_approvers,json=nodeApprovers,proto3" json:"node_approvers,omitempty"`
}

type ApprovalWorkflowsData struct {
	ProjectId   string                       `protobuf:"bytes,1,opt,name=project_id,json=projectId,proto3" json:"project_id,omitempty"`
	ProjectName string                       `protobuf:"bytes,2,opt,name=project_name,json=projectName,proto3" json:"project_name,omitempty"`
	RegionName  string                       `protobuf:"bytes,3,opt,name=region_name,json=regionName,proto3" json:"region_name,omitempty"`
	RegionId    string                       `protobuf:"bytes,4,opt,name=region_id,json=regionId,proto3" json:"region_id,omitempty"`
	BizScene    string                       `protobuf:"bytes,5,opt,name=biz_scene,json=bizScene,proto3" json:"biz_scene,omitempty"`
	Index       int32                        `protobuf:"varint,6,opt,name=index,proto3" json:"index,omitempty"`
	NodeList    []*ApprovalWorkflowsNodeList `protobuf:"bytes,7,rep,name=node_list,json=nodeList,proto3" json:"node_list,omitempty"`
}

// 练习处理多级数组数据
func main() {
	fmt.Println("练习处理多级数组数据")
	jsonData := `[
   {
       "ProjectId": "38d97f94-2aac-4cd0-8ee8-2a536d13f57c",
       "ProjectName": "大铲湾企鹅公寓05项目",
       "RegionName": "深圳",
       "RegionId": "eb557454-acc7-477b-810c-67168f61344d",
       "BizScene": "Price",
       "Index": 0,
       "NodeId": "f614f2f1-8bf0-4ac3-a8b6-9abaed9484c3",
       "NodeName": "业务leader审批",
       "NodeOrder": 1,
       "NodeApproverEnname": "boneyxiang",
       "NodeApproverCnname": "向阳",
       "Status": 1
   },
   {
       "ProjectId": "38d97f94-2aac-4cd0-8ee8-2a536d13f57c",
       "ProjectName": "大铲湾企鹅公寓05项目",
       "RegionName": "深圳",
       "RegionId": "eb557454-acc7-477b-810c-67168f61344d",
       "BizScene": "Price",
       "Index": 0,
       "NodeId": "7b87c2aa-afb3-4466-b97c-bf507c35660f",
       "NodeName": "财管leader审批",
       "NodeOrder": 2,
       "NodeApproverEnname": "jeremyyou",
       "NodeApproverCnname": "游俊杰",
       "Status": 1
   },
   {
       "ProjectId": "38d97f94-2aac-4cd0-8ee8-2a536d13f57c",
       "ProjectName": "大铲湾企鹅公寓05项目",
       "RegionName": "深圳",
       "RegionId": "eb557454-acc7-477b-810c-67168f61344d",
       "BizScene": "Price",
       "Index": 0,
       "NodeId": "f614f2f1-8bf0-4ac3-a8b6-9abaed9484c3",
       "NodeName": "业务leader审批",
       "NodeOrder": 1,
       "NodeApproverEnname": "yeahxu",
       "NodeApproverCnname": "许蒙",
       "Status": 1
   },
   {
       "ProjectId": "38d97f94-2aac-4cd0-8ee8-2a536d13f57c",
       "ProjectName": "大铲湾企鹅公寓05项目",
       "RegionName": "深圳",
       "RegionId": "eb557454-acc7-477b-810c-67168f61344d",
       "BizScene": "PriceDiscount",
       "Index": 0,
       "NodeId": "9dd580db-dfd3-49f0-8950-345d4eba2f56",
       "NodeName": "业务leader审批",
       "NodeOrder": 1,
       "NodeApproverEnname": "boneyxiang",
       "NodeApproverCnname": "向阳",
       "Status": 1
   },
   {
       "ProjectId": "38d97f94-2aac-4cd0-8ee8-2a536d13f57c",
       "ProjectName": "大铲湾企鹅公寓05项目",
       "RegionName": "深圳",
       "RegionId": "eb557454-acc7-477b-810c-67168f61344d",
       "BizScene": "PriceDiscount",
       "Index": 0,
       "NodeId": "9dd580db-dfd3-49f0-8950-345d4eba2f56",
       "NodeName": "业务leader审批",
       "NodeOrder": 1,
       "NodeApproverEnname": "liviapeng",
       "NodeApproverCnname": "彭慧琳",
       "Status": 1
   },
   {
       "ProjectId": "38d97f94-2aac-4cd0-8ee8-2a536d13f57c",
       "ProjectName": "大铲湾企鹅公05项目",
       "RegionName": "深圳",
       "RegionId": "eb557454-acc7-477b-810c-67168f61344d",
       "BizScene": "PriceDiscount",
       "Index": 0,
       "NodeId": "38de978a-0c9c-46e8-8b9a-3e3ef30af7e2",
       "NodeName": "财管leader审批",
       "NodeOrder": 2,
       "NodeApproverEnname": "jeremyyou",
       "NodeApproverCnname": "游俊杰",
       "Status": 1
   },
   {
       "ProjectId": "38d97f94-2aac c-4cd0-8ee8-2a536d13f57c",
       "ProjectName": "大铲湾企鹅公寓05项目",
       "RegionName": "深圳",
       "RegionId": "eb557454-acc7-477b-810c-67168f61344d",
       "BizScene": "PriceDiscount",
       "Index": 0,
       "NodeId": "38de978a-0c9c-46e8-8b9a-3e3ef30af7e2",
       "NodeName": "财管leader审批",
       "NodeOrder": 2,
       "NodeApproverEnname": "yeahxu",
       "NodeApproverCnname": "许蒙",
       "Status": 1
   }
]`
	str := []byte(jsonData)

	var data []GetApprovalWorkflowConfigData

	err := json.Unmarshal(str, &data)
	if err != nil {
		fmt.Println(err)
	}

	// 遍历处理数据结构
	NodeId := ""
	BizScene := ""
	ProjectId := ""
	// 以 NodeId 作为区分数据
	var NodeApprovers []*ApprovalWorkflowsNodeApprovers
	var NodeList []*ApprovalWorkflowsNodeList
	var DataList []*ApprovalWorkflowsData
	for _, record := range data {
		if NodeId == "" {
			NodeId = record.NodeId
		} else { // 对比当前node_id是否相同,相同就继续append 否则就重置后新加一个数组
			if NodeId != record.NodeId {
				NodeApprovers = nil // 把数组置空
			}
		}
		// 添加三级node内容 node_id 作为判断条件
		NodeApprovers = append(NodeApprovers, &ApprovalWorkflowsNodeApprovers{
			NodeApproverEnname: record.NodeApproverEnname,
			NodeApproverCnname: record.NodeApproverCnname,
			Status:             record.Status,
		})

		// 添加二级node内容 biz_scene 作为判断条件
		if BizScene == "" {
			BizScene = record.BizScene
		} else if BizScene != record.BizScene {
			NodeList = nil
		}
		NodeList = append(NodeList, &ApprovalWorkflowsNodeList{
			NodeId:        record.NodeId,
			NodeName:      record.NodeName,
			NodeOrder:     record.NodeOrder,
			NodeApprovers: NodeApprovers,
		})

		if ProjectId == "" {
			ProjectId = record.ProjectId
		} else {
			if ProjectId != record.ProjectId {
				DataList = nil
			}
		}
		DataList = append(DataList, &ApprovalWorkflowsData{
			ProjectId:   record.ProjectId,
			ProjectName: record.ProjectName,
			RegionName:  record.RegionName,
			RegionId:    record.RegionId,
			BizScene:    record.BizScene,
			Index:       0,
			NodeList:    NodeList,
		})
	}
	fmt.Println("--------------------------------------------------------------------------")

}

// TestEmptyArr 清空数组内容
func TestEmptyArr() {
	var ddd []ApprovalWorkflowsNodeApprovers
	ddd = append(ddd, ApprovalWorkflowsNodeApprovers{
		NodeApproverEnname: "daf",
		NodeApproverCnname: "dafd",
		Status:             1,
	})
	ddd = append(ddd, ApprovalWorkflowsNodeApprovers{
		NodeApproverEnname: "aaa",
		NodeApproverCnname: "ddd",
		Status:             2,
	})
	fmt.Println(ddd)
	if len(ddd) > 1 {
		ddd = nil
		ddd = append(ddd, ApprovalWorkflowsNodeApprovers{
			NodeApproverEnname: "eee",
			NodeApproverCnname: "fff",
			Status:             2,
		})
	}
	fmt.Println(ddd)
}
